#!/usr/bin/env node

const http = require('http');
const fs = require('fs');

//json 解析-> book_cover_urls
function getcoverURLs() {
    let data =  fs.readFileSync('./book-1.json', 'utf8');
    data = JSON.parse(data).UpdateComicItems;
    return data.map(book => book.ShowConver);
} 

//get cover from urls
function getBookCover (){
    const urls = getcoverURLs();
    let i = 1;

    urls.forEach(url => {
        http.get(url, res => {
            res.pipe(fs.createWriteStream(`./cover/${i++}.jpg`));
        });
    })
}

getBookCover();
